get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(__DIR "${_DIR}" PATH)
# 检查生成的文件是否存在
include(${__DIR}/config/cmake_config.cmake)



# -------------------------------
# 1. 基本系统信息
# -------------------------------
message("")
message("📊 构建系统诊断信息")
message("───────────────────────────")
message(STATUS "操作系统:        ${CMAKE_SYSTEM_NAME}")
message(STATUS "系统版本:        ${CMAKE_SYSTEM_VERSION}")
message(STATUS "主机系统:        ${CMAKE_HOST_SYSTEM}")
message(STATUS "目标系统:        ${CMAKE_SYSTEM}")

# -------------------------------
# 2. CPU 架构 / 处理器信息
# -------------------------------
message(STATUS "处理器架构:     ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "主机处理器:     ${CMAKE_HOST_SYSTEM_PROCESSOR}")

# 注意：CMake 不直接提供“核心数”，但可通过命令获取
execute_process(
    COMMAND sh -c "nproc || sysctl -n hw.ncpu || echo 1"
    OUTPUT_VARIABLE CORES
    OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "CPU 核心数:       ${CORES}")

# -------------------------------
# 3. 编译器信息
# -------------------------------
message(STATUS "C 编译器 ID:      ${CMAKE_C_COMPILER_ID}")
message(STATUS "C 编译器路径:    ${CMAKE_C_COMPILER}")
message(STATUS "C 编译器版本:    ${CMAKE_C_COMPILER_VERSION}")

message(STATUS "C++ 编译器 ID:    ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "C++ 编译器路径:  ${CMAKE_CXX_COMPILER}")
message(STATUS "C++ 编译器版本:  ${CMAKE_CXX_COMPILER_VERSION}")

# 如果是 Clang，打印是否为 LLD 或其他
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
    message(STATUS "Clang 目标:       ${CMAKE_C_COMPILER_TARGET}")
endif()

# -------------------------------
# 4. 构建类型与配置
# -------------------------------
message(STATUS "构建类型:         ${CMAKE_BUILD_TYPE}")
message(STATUS "生成器:           ${CMAKE_GENERATOR}")
message(STATUS "64位构建:         ${CMAKE_SIZEOF_VOID_P} 字节")

# 判断是 32 还是 64 位
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    message(STATUS "指针大小:         64-bit")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
    message(STATUS "指针大小:         32-bit")
else()
    message(STATUS "指针大小:         ${CMAKE_SIZEOF_VOID_P} 字节")
endif()

# -------------------------------
# 5. Android / 交叉编译 特有信息
# -------------------------------
if(ANDROID)
    message(STATUS "🎯 Android 模式:   启用")
    message(STATUS "ABI:              ${ANDROID_ABI}")
    message(STATUS "NDK 版本:         ${ANDROID_NDK_VERSION}")
    message(STATUS "API 级别:         ${ANDROID_API}")
    message(STATUS "工具链根目录:    ${ANDROID_TOOLCHAIN_ROOT}")
    message(STATUS "SYSROOT:         ${ANDROID_SYSROOT}")
    message(STATUS "三元组:           ${ANDROID_TOOLCHAIN_NAME}")
endif()

# -------------------------------
# 6. iOS 特有信息（可选）
# -------------------------------
if(IOS OR APPLE AND CMAKE_OSX_SYSROOT MATCHES "iphoneos")
    message(STATUS "🍏 iOS 模式:        启用")
    message(STATUS "平台:             ${CMAKE_OSX_SYSROOT}")
    message(STATUS "架构:             ${CMAKE_OSX_ARCHITECTURES}")
endif()

# -------------------------------
# 7. 其他有用信息
# -------------------------------
message(STATUS "源码目录:         ${CMAKE_SOURCE_DIR}")
message(STATUS "构建目录:         ${CMAKE_BINARY_DIR}")
message(STATUS "主机名:           ${CMAKE_HOST_SYSTEM_NAME}")
message(STATUS "字节序:           ${CMAKE_BYTE_ORDER}")

# 可选：打印所有缓存变量（用于调试）
 get_cmake_property(_vars CACHE_VARIABLES)
foreach(_var ${_vars})
#     message(STATUS "CACHE: ${_var} = ${${_var}}")
endforeach()

# 手动设置 optflags
set(OPTFLAGS "-O2 -DNDEBUG -march=x86-64")

# 应用到 C/C++
message(STATUS "c 编译选项:           ${CMAKE_C_FLAGS_RELEASE}")
message(STATUS "c++ 编译选项:           ${CMAKE_CXX_FLAGS_RELEASE}")



# -------------------------------
# 添加一个空目标以便 cmake 能运行
# -------------------------------
# add_custom_target(diag_info ALL COMMENT "✅ 系统信息打印完成" VERBATIM)
